﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="frmRelationship.ascx.cs" Inherits="GUESTSMANAGEMENT.View.Event.frmRelationship" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>

<ext:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
</ext:ScriptManagerProxy>

<script type="text/javascript">
    var openWindowRelEvent = function()
    {
        var winRel = <%= winRel.ClientID %>;
        winRel.show();
    }
    
    function alertMessage() {
        relEventGridPanel = eval('<%=GridPanelRelEvent.ClientID%>');
        if (relEventGridPanel.hasSelection())
            return "Confirma Exclusão? <br> <b>" + relEventGridPanel.getSelectionModel().getSelected().data.NMUSER + "</b>";

    }
</script>

<ext:TokenScript runat="server">
    <script type="text/javascript">
        var applyFilter = function () {
            #{userStore}.filterBy(getRecordFilter());
        }
        
        var clearFilter = function () {
            #{userNameFilter}.reset();
            #{userStore}.clearFilter();
        }

        var filterString = function (value, dataIndex, record) {
            var val = record.get(dataIndex);
            if (typeof val != "string") {
                return value.length == 0;
            }
            return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
        }

        var getRecordFilter = function () {
            var f = [];

            f.push({
                filter: function(record) {                         
                    return filterString(#{userNameFilter}.getValue(), 'NMUSER', record);
                }
            });
            
            var len = f.length;
            return function(record) {
                for (var i = 0; i < len; i++) {
                    if (!f[i].filter(record)) {
                        return false;
                    }
                }
                return true;
            };
        }  
    </script>
</ext:TokenScript>

<ext:Window ID="winRel" 
            runat="server" 
            Collapsible="false" 
            Icon="World" 
            Title="Cadastro de Eventos" 
            ShowOnLoad="false" 
            Width="511" 
            Height="493" 
            Resizable="false"
            Maximizable="false">
        <Body>
            <ext:Hidden ID="idEvent" runat="server" />
            <ext:Store ID="userStore" runat="server" OnRefreshData="Refresh" RefreshAfterSaving="Auto">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="CDUSER" />
                            <ext:RecordField Name="IDUSER" />
                            <ext:RecordField Name="NMUSER" />
                            <ext:RecordField Name="NMMAIL" />
                            <ext:RecordField Name="NMPHONE" />
                            <ext:RecordField Name="FGUSER" />
                            <ext:RecordField Name="FGENABLED" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            <ext:GridPanel 
                ID="GridPanelRelEvent" 
                runat="server" 
                StoreID="userStore"
                StripeRows="true"
                Collapsible="true"
                Width="498"
                Height="460">
                <TopBar>
                    <ext:Toolbar ID="ToolBar1" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="btnNewEvent" runat="server" Icon="WorldAdd" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="SubmitSelection">
                                        <ExtraParams>
                                            <ext:Parameter Name="Values" Value="Ext.encode(#{GridPanelRelEvent}.getRowsValues())" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipNewEvent" runat="server" Html="Novo Evento"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
	                <Columns>
                        <ext:Column ColumnId="NMUSER" Header="Nome" Width="476" Sortable="true" DataIndex="NMUSER" />
                        <ext:Column ColumnId="CDUSER" Hidden="true" Sortable="true" DataIndex="CDUSER" />
	                </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionMode" runat="server">
                        <Listeners>
                            <RowSelect Handler="#{btnNewEvent}.enable();" />                             
                            <RowDeselect Handler="if (!#{GridPanelRelEvent}.hasSelection()) {#{btnNewEvent}.disable(); }" />
                        </Listeners>
                    </ext:RowSelectionModel>
                </SelectionModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                        <HeaderRows>
                            <ext:HeaderRow>
                                <Columns>             
                                    <ext:HeaderColumn Cls="x-small-editor">
                                        <Component>
                                            <ext:TextField ID="userNameFilter" runat="server" EnableKeyEvents="true">
                                                <Listeners>
                                                    <KeyUp Handler="applyFilter();" Buffer="250" />
                                                </Listeners>
                                            </ext:TextField>
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn AutoWidthElement="false">
                                        <Component>
                                            <ext:Button ID="ClearFilterButton" runat="server" Icon="Cross">
                                                <ToolTips>
                                                    <ext:ToolTip ID="ToolTip1" runat="server" Html="Limpar Filtros" />
                                                </ToolTips>
                                                <Listeners>
                                                    <Click Handler="clearFilter();" />
                                                </Listeners>
                                            </ext:Button>
                                        </Component>
                                    </ext:HeaderColumn>
                                </Columns>
                            </ext:HeaderRow>
                        </HeaderRows>
                    </ext:GridView>
                </View>
             </ext:GridPanel>
        </Body>
</ext:Window>
